package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.SchClazz;
import com.ruoyi.teach.service.ISchClazzService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/clazz")
public class SchClazzController extends BaseController
{
    @Autowired
    private ISchClazzService schClazzService;

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('teach:clazz:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchClazz schClazz)
    {
        startPage();
        List<SchClazz> list = schClazzService.selectSchClazzList(schClazz);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @PreAuthorize("@ss.hasPermi('teach:clazz:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchClazz schClazz)
    {
        List<SchClazz> list = schClazzService.selectSchClazzList(schClazz);
        ExcelUtil<SchClazz> util = new ExcelUtil<SchClazz>(SchClazz.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:clazz:query')")
    @GetMapping(value = "/{cId}")
    public AjaxResult getInfo(@PathVariable("cId") Long cId)
    {
        return AjaxResult.success(schClazzService.selectSchClazzByCId(cId));
    }

    /**
     * 新增班级
     */
    @PreAuthorize("@ss.hasPermi('teach:clazz:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchClazz schClazz)
    {
        return toAjax(schClazzService.insertSchClazz(schClazz));
    }

    /**
     * 修改班级
     */
    @PreAuthorize("@ss.hasPermi('teach:clazz:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchClazz schClazz)
    {
        return toAjax(schClazzService.updateSchClazz(schClazz));
    }

    /**
     * 删除班级
     */
    @PreAuthorize("@ss.hasPermi('teach:clazz:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cIds}")
    public AjaxResult remove(@PathVariable Long[] cIds)
    {
        return toAjax(schClazzService.deleteSchClazzByCIds(cIds));
    }
}
